import request from '@/utils/request';
import { IFloor, IFloorForm, IApiResponse } from '@/pages/List/FloorManage/consts';

/**
 * 获取楼层列表
 * @returns 
 */
export function getFloorListAPI(): Promise<IApiResponse<IFloor[]>> {
  return request({
    url: '/floors',
    method: 'GET',
  });
}

/**
 * 获取指定楼层的包间信息
 * @returns 
 */
export async function getRoomListByFloorIdAPI(id: number) {
  return request.get(`/floors/${id}/rooms`);
}

/**
 * 创建楼层
 * @param data 楼层数据
 * @returns 
 */
export function addFloorAPI(data: IFloorForm): Promise<IApiResponse<IFloor>> {
  return request({
    url: '/floors',
    method: 'POST',
    data,
  });
}

/**
 * 删除楼层
 * @param id 楼层id
 * @returns 
 */
export function deleteFloorAPI(id: number): Promise<IApiResponse<null>> {
  return request({
    url: `/floors/${id}`,
    method: 'DELETE',
  });
}

/**
 * 更新楼层
 * @param id 楼层id
 * @param data 更新后的楼层数据
 * @returns 
 */
export function updateFloorAPI(id: number, data: Partial<IFloorForm>): Promise<IApiResponse<IFloor>> {
  return request({
    url: `/floors/${id}`,
    method: 'PUT',
    data,
  });
}
